package com.tianji.learning.service.impl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.tianji.common.exceptions.BizIllegalException;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.mapper.PointsBoardSeasonMapper;
import com.tianji.learning.service.IPointsBoardSeasonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 老李头儿
 * @since 2025-04-03
 */
@Service
public class PointsBoardSeasonServiceImpl extends ServiceImpl<PointsBoardSeasonMapper, PointsBoardSeason> implements IPointsBoardSeasonService {

    /**
    * @Description 查询赛季时间
    * @Author 老李头儿
    * @Date 2025年04月03 10:43:29
    * @param time
    * @Return java.lang.Integer
    **/

    @Override
    public Integer querySeasonByTime(LocalDateTime time) {
        // begin end ==> create_time
        // select * from table where create_time >= begin and create_time <= end

        // time ==> begin_time end_time
        // select * from table where time >= begin_time and time <= end_time

        PointsBoardSeason season = lambdaQuery()
                .le(PointsBoardSeason::getBeginTime, time)
                .ge(PointsBoardSeason::getEndTime, time)
                .one();
        if(ObjectUtils.isEmpty(season)){
            log.error("赛季信息不存在");
            throw new BizIllegalException("赛季信息不存在");
        }
        return season.getId();
    }
}
